package test4;
import java.util.Scanner;
public class StringDemo {
    public static void main(String[] args) {
        //键盘输入金额
        Scanner sc=new Scanner(System.in);
        //判断金额是否合法
        int money;
        while(true){
            System.out.println("请输入金额");
            money=sc.nextInt();
            if(money>=0&&money<=9999999){
                break;
            }
            else{
                System.out.println("金额不合法");
            }
        }
        //对金额进行拆分,调用一个方法，将阿拉伯数字转化为汉字数字，并进行拼接
        String strMoney="";
        int count=0;
        while(true){
            if(money==0){
                break;
            }
            else{
                int ge=money%10;
                money/=10;
                CapticalNumber(ge);
                strMoney=CapticalNumber(ge)+strMoney;
                count++;
            }
        }
        //System.out.println(strMoney);
        //在数字前补充“零”，满七位
        int count2=7-count;
        if(count2!=0){
            for (int i = 0; i < 7-count; i++) {
                strMoney="零"+strMoney;
            }
        }
        //System.out.println( strMoney);
        //遍历strMoney，在数字中间插入单位（拼接）
        String arr[]={"佰","拾","万","仟","佰","拾","元"};
        String result="";
        for (int i = 0; i < strMoney.length(); i++) {
            char c=strMoney.charAt(i);
            result=result+c+arr[i];
        }
        System.out.println(result);
    }
    public  static String CapticalNumber(int number) {
        String[] arr={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return arr[number];
    };
}
